package org.miku.junit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.util.List;

import org.junit.After;
import org.junit.Test;
import org.miku.db.SQLHelper;
import org.miku.module.note.NoteInfo;
import org.miku.module.note.NoteManager;
import org.miku.tools.Tools;

public class NoteManagerTest {
	SQLHelper sqlHelper = new SQLHelper("localhost",
			3306, "db_onlinenote", "root", "aihejuhuacha");
	NoteManager noteMgr = new NoteManager(sqlHelper);
	
	@After
	public void connectClose() {
		sqlHelper.close();
	}

	// @Test
	public void testAddNote() {
		NoteInfo info = new NoteInfo();
		info.setAuthor("Mason");
		info.setTitle("This is a title");
		info.setContent("This is my first note.");
		info.setCreateTime(Tools.getTime());
		assertEquals(true, noteMgr.addNote(info));
	}

	// @Test
	public void testDelNote() {
		noteMgr.delNote(1);
	}

	// @Test
	public void testModifyNote() {
		NoteInfo info = new NoteInfo();
		info.setNoteId(2);
		info.setContent("Change content!");
		noteMgr.modifyNote(info);
	}

	// @Test
	public void testGetNoteListByName() {
		fail("Not yet implemented");
	}

	// @Test
	public void testGetNoteListByKeyword() {
		List<NoteInfo> list = noteMgr.getNoteListByKeyword("first");
		assertEquals(1, list.size());
	}

	// @Test
	public void testGetNoteInfo() {
		NoteInfo info = noteMgr.getNoteInfo(1);
		if(info != null) {
			assertEquals("Mason", info.getAuthor());
		}
	}

}